<?php 
/* P3(c)

******************************************************************************
                                                                                      
                         __                                                        
                        /__)                                                       
                       /__        P3 - moving Technologie            
                        __)                                                          
                        __)                                                          
                                                                                        
                                                                                        
       Copyright 2009 by p3.co.at                                                                                 
                                                                                        
       visit www.p3.co.at to get more Informations 
       about Teriko - Betriebsdatenerfassung                                                                                 
       - it's not allowed to change this scripts
       - it's not allowed to remove this copyright-tag

       -- you can download the complete license   
          under http://www.teriko.org

 (c) by Patrik Pfaffenbauer and P3 (http://www.p3.co.at)

 | Programname: P3.Teriko
 | Authtor: P3.Verein
 | Coder: Patrik Pfaffenbauer
 | Version: 0.1

 | Change Index
 |_____________________________________________
 |                                             |
 |4.3.2010 Erstellung | Patrik Pfaffenbauer    |
 |_____________________________________________|

******************************************************************************

P3(c) */

class Test extends Base2
{
	
	public function Test()
	{
		$this->toolbar = true;
	 	$this->db = new Database();
	}
	
	public function AnalysPost()
	{
		include("./_tables.php");
		
		if($_POST['action'] == "add" || $_POST['action'] == "copy")
		{
			$this->Add();
		}
		else if($_POST['action'] == "save")
		{
			$GLOBALS['db']->SaveObject($tblcustomer);
			$this->Paint();
		}
		else if($_POST['action'] == "update")
		{
			$GLOBALS['db']->UpdateObject($tblcustomer);
			$this->Paint();
		}
		else if($_POST['action'] == "ShowReport")
		{
			$this->ShowReport();
		}
		else
		{
			$this->Paint();
		}
	}
	
	public function ShowReport()
	{
		$jasper_url = "http://10.40.99.235:8088/jasperserver-pro/services/repository";  
   		$jasper_username = "web";  
   		$jasper_password = "google";  
      
     
   		$client = new JasperClient($jasper_url, $jasper_username, $jasper_password);  
     
  		$report_unit = "/reports/samples/EmployeeAccounts";  
  		$report_format = "PDF";  
 		//$report_params = array('foo' => 'bar', 'fruit' => 'apple');  
   
 		$result = $client->requestReport($report_unit, $report_format,"");  
    
  		header('Content-type: application/pdf');  
  		echo $result;  
	}
	
	public function Add()
	{
		$smarty = GetSmarty();
		$smarty->assign("editPanel", true);
	 	
		if($this->error)
		{
			$smarty->assign("error",  $this->errorText);
		}
		
		if($_POST['action'] == "add" && !$this->error)
		{
			foreach($_POST as $key => $value)
			{	
				$_POST[$key] = "";
			}
		}


		$smarty->assign("langNameValue",  $_POST['name']);
		$smarty->assign("langStreetValue",  $_POST['street']);
		$smarty->assign("langCityValue",  $_POST['city']);
		$smarty->assign("langTelValue",  $_POST['telephon']);
		$smarty->assign("type", "save");
		$smarty->assign('hiddenFields', array( 
							array('name' => 'action','value' => 'save'),
                            array('name' => 'option','value' => 'member')));
                            
	
		$smarty->display('test.tpl');
	}
	
	public function Paint()
	{
		include("./_tables.php");
		$this->dataTable = $tblcustomer;
		$this->PaintEditPanel();
		
		$this->smarty->assign("editPanel", true);
	 	
		
		if($this->error)
		{
			$this->smarty->assign("error",  $this->errorText);
		}
		
		if($this->hasData)
		{
			$this->smarty->assign("langNameValue",  $this->data->name);
			$this->smarty->assign("langStreetValue",  $this->data->street);
			$this->smarty->assign("langCityValue",  $this->data->city);
			$this->smarty->assign("langTelValue",  $this->data->telephone);	
		}
		
		$this->smarty->assign("type", $type);
			
		$type = ($_POST['id'] != "") ? "update" : "save";
				
		$this->smarty->assign('hiddenFields', array( 
					array('name' => 'action','value' => $type),
                    array('name' => 'option','value' => 'member'),
                    array('name' => 'id','value' => $this->data->id),
                    array('name' => 'search','value' => ($_POST ['search'] != "") ? $_POST['search'] : $this->search)));
		
		$this->smarty->display('test.tpl');
	
	}
	
	public function Toolbar()
	{
		
	}

	public function AddCSS()
	{
		echo '<link rel="stylesheet" type="text/css" href="css/p3/autocompleter.css" />';
	
	}
	public function AddJS()
	{
		echo '
		
		<script type="text/javascript" src="js/autocompleter/Autocompleter.js"></script>
		<script type="text/javascript" src="js/autocompleter/Autocompleter.Request.js"></script>
		<script type="text/javascript" src="js/autocompleter/Observer.js"></script>
		
		
		<script type="text/javascript">
		window.addEvent(\'domready\', function() {
 
		    //new Autocompleter.Request.JSON(\'test\', \'autocompleter.php\', {\'postVar\': \'search\'});
		    
		    new Autocompleter.Request.JSON(\'test\', \'autocompleter.php\', 
		    {
				\'postVar\': \'search\',
				autoSubmit: false,
				onRequest: function() 
				{
					$(\'test2\').value = \'Request\';
				},
				onComplete: function() 
				{
					$(\'test2\').value = \'done\';
				}
				}); 
			});
		
		</script>
		';
	}
}

?>